From e214e5c6c11ea61a9e256574b50dcab5852d62c0 Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Thu, 13 Jan 2005 11:56:17 +0000 Subject: [PATCH] bitkeeper revision 1.1159.170.93 (41e661e138UbGRYHtgaE3FTrqTgzzw) Add VIF-routing capability to xend. The default is still to bridge. --- .rootkeys | 2 + tools/examples/Makefile | 4 +- tools/examples/network-route | 19 +++++++++ tools/examples/vif-route | 76 ++++++++++++++++++++++++++++++++++ tools/examples/xend-config.sxp | 9 +++- tools/python/xen/xm/create.py | 8 +++- 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100755 tools/examples/network-route create mode 100755 tools/examples/vif-route diff --git a/.rootkeys b/.rootkeys index 89187e42af..9f7ea4cd17 100644 --- a/.rootkeys +++ b/.rootkeys @@ -314,7 +314,9 @@ 405ff55dawQyCHFEnJ067ChPRoXBBA tools/examples/init.d/xend 40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/init.d/xendomains 40ee75a9xFz6S05sDKu-JCLqyVTkDA tools/examples/network +41e661e1giIEKbJ25qfiP-ke8u8hFA tools/examples/network-route 40ee75a967sxgcRY4Q7zXoVUaJ4flA tools/examples/vif-bridge +41e661e1ooiRKlOfwumG6wwzc0PdhQ tools/examples/vif-route 40ee75a93cqxHp6MiYXxxwR5j2_8QQ tools/examples/xend-config.sxp 41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmexample1 40cf2937oKlROYOJTN8GWwWM5AmjBg tools/examples/xmexample2 diff --git a/tools/examples/Makefile b/tools/examples/Makefile index 1e77f89d50..14f18ae84f 100644 --- a/tools/examples/Makefile +++ b/tools/examples/Makefile @@ -11,8 +11,8 @@ XEN_CONFIGS += xmexample2 # Xen script dir and scripts to go there. XEN_SCRIPT_DIR = /etc/xen/scripts -XEN_SCRIPTS = network -XEN_SCRIPTS += vif-bridge +XEN_SCRIPTS = network vif-bridge +XEN_SCRIPTS += network-route vif-route XEN_SCRIPTS += block-file XEN_SCRIPTS += block-enbd diff --git a/tools/examples/network-route b/tools/examples/network-route new file mode 100755 index 0000000000..cb217c068d --- /dev/null +++ b/tools/examples/network-route @@ -0,0 +1,19 @@ +#!/bin/sh +#============================================================================ +# Default Xen network start/stop script. +# Xend calls a network script when it starts. +# The script name to use is defined in /etc/xen/xend-config.sxp +# in the network-script field. +# +# Usage: +# +# network-route (start|stop|status) {VAR=VAL}* +# +# Vars: +# +# netdev The gateway interface (default eth0). +# antispoof Whether to use iptables to prevent spoofing (default yes). +# +#============================================================================ + +echo 1 >/proc/sys/net/ipv4/ip_forward diff --git a/tools/examples/vif-route b/tools/examples/vif-route new file mode 100755 index 0000000000..b15aea1e5c --- /dev/null +++ b/tools/examples/vif-route @@ -0,0 +1,76 @@ +#!/bin/sh +#============================================================================ +# /etc/xen/vif-route +# +# Script for configuring a vif in routed mode. +# Xend calls a vif script when bringing a vif up or down. +# This script is the default - but it can be configured for each vif. +# +# Example invocation: +# +# vif-route up domain=VM1 vif=vif1.0 ip="128.232.38.45/28 10.10.10.55/24" +# +# Usage: +# vif-route (up|down) {VAR=VAL}* +# +# Vars: +# +# domain name of the domain the interface is on (required). +# vif vif interface name (required). +# mac vif MAC address (required). +# ip list of IP networks for the vif, space-separated (optional). +#============================================================================ + +# Exit if anything goes wrong +set -e + +echo "vif-route $*" + +# Operation name. +OP=$1 +shift + +# Pull variables in args into environment +for arg ; do export "${arg}" ; done + +# Required parameters. Fail if not set. +domain=${domain:?} +vif=${vif:?} +mac=${mac:?} + +# Optional parameters. Set defaults. +ip=${ip:-''} # default to null (do nothing) + +main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'` + +# Are we going up or down? +case $OP in + up) + ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up + echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp + iptcmd='-A' + ipcmd='a' + ;; + down) + ifconfig ${vif} down + iptcmd='-D' + ipcmd='d' + ;; + *) + echo 'Invalid command: ' $OP + echo 'Valid commands are: up, down' + exit 1 + ;; +esac + +if [ ${ip} ] ; then + + # If we've been given a list of IP networks, allow pkts with these src addrs. + for addr in ${ip} ; do + ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip} +# iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT + done + + # Always allow us to talk to a DHCP server anyhow. +# iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT +fi diff --git a/tools/examples/xend-config.sxp b/tools/examples/xend-config.sxp index ee5dbbc0a3..a62b112519 100644 --- a/tools/examples/xend-config.sxp +++ b/tools/examples/xend-config.sxp @@ -8,12 +8,17 @@ # Specifying the empty string '' allows all connections. (xend-address '') +## Use the following if VIF traffic is routed. # The script used to start/stop networking for xend. -(network-script network) +#(network-script network-route) +# The default script used to control virtual interfaces. +#(vif-script vif-route) +## Use the following if VIF traffic is bridged. +# The script used to start/stop networking for xend. +(network-script network) # The default bridge that virtual interfaces should be connected to. (vif-bridge xen-br0) - # The default script used to control virtual interfaces. (vif-script vif-bridge) diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index 9d977dd337..03f815eddb 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -283,14 +283,18 @@ def configure_vifs(config_devs, vals): if idx < len(vifs): d = vifs[idx] mac = d.get('mac') + if not mac: + mac = randomMAC() bridge = d.get('bridge') script = d.get('script') backend = d.get('backend') + ip = d.get('ip') else: mac = randomMAC() bridge = None script = None backend = None + ip = None config_vif = ['vif'] config_vif.append(['mac', mac]) if bridge: @@ -299,6 +303,8 @@ def configure_vifs(config_devs, vals): config_vif.append(['script', script]) if backend: config_vif.append(['backend', backend]) + if ip: + config_vif.append(['ip', ip]) config_devs.append(['device', config_vif]) def configure_vfr(config, vals): @@ -377,7 +383,7 @@ def preprocess_vifs(opts, vals): (k, v) = b.strip().split('=', 1) k = k.strip() v = v.strip() - if k not in ['mac', 'bridge', 'script', 'backend']: + if k not in ['mac', 'bridge', 'script', 'backend', 'ip']: opts.err('Invalid vif specifier: ' + vif) d[k] = v vifs.append(d) -- 2.30.2